package com.kaifamiao.jdbc.core;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

// 在 MySQL 8 中 已经将 `com.mysql.jdbc.Driver` 类废弃
// 取而代之的是 `com.mysql.cj.jdbc.Driver`
public class DriverMySQLTest {

    public static void main(String[] args) throws SQLException {

        String url = "jdbc:mysql://localhost:3306/kaifamiao?serverTimezone=Asia/Chongqing";
        String username = "kfm";
        String password = "kfm";

        // 创建驱动类的实例
        Driver driver = new com.mysql.cj.jdbc.Driver();
        System.out.println( driver );

        // 注册驱动
        DriverManager.registerDriver( driver );

        // 获得数据库连接
        Connection conn = DriverManager.getConnection( url, username, password );
        System.out.println( conn );

        // 释放资源
        conn.close();
    }

}
